﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsForms.Class;
using WindowsForms.service;
using Model;

namespace WindowsForms
{
    public partial class rptHistoryBooking : DevExpress.XtraEditors.XtraForm
    {
        Service1 iQuery;
        List<Bookings> lsHistoryBookings;

        public rptHistoryBooking()
        {
            iQuery = new Service1();
            InitializeComponent();

            dateEditFrom.EditValue = DateTime.Now.AddDays(-7);
            dateEditTo.EditValue = DateTime.Now.AddDays(1);
        }

        private void rptHistoryBooking_Load(object sender, EventArgs e)
        {

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            XtraReportBooking report = new XtraReportBooking();

            report.bindData(dateEditFrom.Text, dateEditTo.Text);

            // get data
            ConvertToList convert = new ConvertToList();
            lsHistoryBookings = convert.ConvertTolistBooking(iQuery.SelectBookingsAll().Tables[0]);
            if (lsHistoryBookings != null && lsHistoryBookings.Count > 0)
            {
                report.DataSource = lsHistoryBookings;
            }
            else
            {
                MessageBox.Show("Không có dữ liệu", "Lịch sử", MessageBoxButtons.OK);
            }

            // Bind the report's printing system to the print control. 
            printControl1.PrintingSystem = report.PrintingSystem;

            // Generate the report's print document. 
            report.CreateDocument();
        }
    }
}
